<!--- 简历上传 -->
<template>
  <HPCommonPage :titleText="'简历筛选 / 简历上传'">
    <template v-slot:searchForm>
      <el-form :inline="true" :model="selectData" class="form-box res-form-box">
        <el-form-item label="需求单号：">
          <el-input
            v-model="selectData.demandNo"
            clearable
            placeholder="请输入需求单号"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位名称：">
          <el-input
            v-model="selectData.jobName"
            clearable
            placeholder="请输入岗位名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="状态：">
          <el-select
            v-model="selectData.status"
            placeholder="请选择状态"
            clearable=""
          >
            <el-option
              v-for="item in statusOptions"
              :key="item.key"
              :label="item.label"
              :value="item.key"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </template>
    <template v-slot:searchFormbtn>
      <el-button type="success" size="small" @click="onSearch">查询</el-button>
    </template>
    <template v-slot:table>
      <HPTable
        :tableHeaderItems="tableHeaderItems"
        :tableData="tableData"
        :loading="isLoad"
      >
      </HPTable>
    </template>
    <template v-slot:pagination>
      <el-pagination
        v-if="totals"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="selectData.currentPage"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="selectData.pageSize"
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="totals"
      >
      </el-pagination>
    </template>
  </HPCommonPage>
</template>
<script>
import HPCommonPage from "@/components/HPCommonPage";
import HPTable from "@/components/HPTable";
import { resumeUploadTableColumn } from "../js/cloumn";
import { resumeUploadStatus } from "../js/status";
import getQuery from '@/utils/mixins/getQuery';
import { remind } from '@/fetch/api'
function fetchResumeLists(store, opts) {
  return store.dispatch("FETCH_RESUMES", opts);
}
export default {
  mixins: [getQuery],
  components: {
    HPCommonPage,
    HPTable,
  },
  data() {
    return {
      selectData: {
        // 查询条件对象
        demandNo: "",
        jobName: "",
        sendName: "",
        status: "",
        currentPage: 1,
        pageSize: 10,
        state: "",
      },
      statusOptions: resumeUploadStatus,
      tableHeaderItems: resumeUploadTableColumn, // table字段
      tableData: [], // table数据
      totals: 0, // 总条数
      isLoad: true,
    };
  },
  created() {
    this.loadTableLists();
  },
  methods: {
    onRemind(row) {
      remind({
        originId: row.needsId,
        remindCode: 'remind_01'
      }).then(res => {
        const { state, message } = res.data
        if(state === '0000') {
          this.$message({
            message: message,
            type: 'success',
            duration: 1500,
          });
          this.loadTableLists()
        }
      })
    },
    // * 获取table数据
    loadTableLists() {
      this.isLoad = true;
      fetchResumeLists(this.$store, {
        ...this.selectData,
      }).then(() => {
        let tempObj = this.$store.getters.getResumeLists;
        if (tempObj.state === "0000") {
          let { list, total, lastPage, pageNum } = tempObj.data;
          this.totals = total;
          this.tableData = list;
          if(pageNum > lastPage && lastPage > 0) {
            this.selectData.currentPage = lastPage
            this.loadTableLists()
          }
        } else {
          this.totals = 0;
          this.tableData = [];
        }
        this.isLoad = false;
      });
    },
    // * 查询
    onSearch() {
      this.selectData.currentPage = 1;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
    // * 查看
    lookResumeDetail({ needsId, state, suspendState }) {
      this.$router.push({
        path: `/resume/detail/${needsId}`,
        query: {
          stus: state,
          formQuery: JSON.stringify(this.searchData),
          suspendState: suspendState
        },
      });
    },
    // * 切换页条数
    handleSizeChange(val) {
      this.selectData.pageSize = val;
      this.selectData.currentPage = 1;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
    // * 切换页数
    handleCurrentChange(val) {
      this.selectData.currentPage = val;
      this.searchData = { ...this.selectData }
      this.loadTableLists();
    },
  },
};
</script>
<style lang="scss"></style>
